Validation #1: Blank Fields

This script will not submit unless the text field has data.

Discussion

This form's text field is placed in focus when the page loads using the focus() method. Any text in the field is selected with the select() method. The form's onSubmit event calls the function validate(), which ensures that the text field has text in it of some sort.
<BODY onLoad="document.forms[0].F1.focus();document.forms[0].F1.select()">

function validate()
{
    if (document.forms[0].F1.value.length == 0)
    {
        alert('You can not submit an empty text field')
        return false
    }
    else
    { 
        alert('About to submit...')
        return true
    }
}
Copyright ©1998 by Charles River Media, All Rights Reserved